package com.yuyou.train.user.api;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.yuyou.train.service.api.user.entity.User;
import com.yuyou.train.service.api.user.entity.UserLessonProgress;
import com.yuyou.train.service.api.user.service.UserLessonProgressAPI;
import com.yuyou.train.user.service.IUserDataConfigService;
import com.yuyou.train.user.service.IUserLessonProgressService;
import com.yuyou.train.user.service.IUserService;

@RestController
public class UserLessonProgressAPIImpl implements UserLessonProgressAPI {

	@Autowired
	private IUserLessonProgressService userLessonProgressService;
	
	@Autowired
	private IUserService userService;
	
	@Autowired
	private IUserDataConfigService userDataConfigService;
	
	@Override
	public UserLessonProgress getUserCurrLesson(
			@RequestParam(value="userId") String userId,
			@RequestParam(value="classId") String classId
			) throws Exception {
		return userLessonProgressService.getUserCurrLesson(userId,classId);
	}

	@Override
	public List<UserLessonProgress> findUserLessonProgress(			
			@RequestParam(value="lessonId")String lessonId,
			@RequestParam(value="status")String status) {
		
		UserLessonProgress userLessonProgress=new UserLessonProgress();
		userLessonProgress.setLessonId(lessonId);
		userLessonProgress.setStatus(status);
		return userLessonProgressService.findUserLessonProgress(userLessonProgress);
	}

	@Override
	public String getUserNextLesson(
			@RequestParam(value="userId") String userId,
			@RequestParam(value="classId") String classId) throws Exception {
		User user=userService.selectByPrimaryKey(userId);		
		String subjectId=userDataConfigService.selectUserSubjectId(userId);		
		String nextLessonId=userLessonProgressService.getUserNextLesson(user.getClassId(), userId, subjectId);		
		return nextLessonId;
	}



}
